package com.naire.modul.answer_sort.dao.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.common.dao.GeneralDaoImpl;
import net.common.service.PageBean;
import net.common.util.BeanUtils;

import com.naire.modul.answer_sort.dao.Answer_sortDao;
import com.naire.modul.answer_sort.pojo.Answer_sort;
import com.naire.modul.answer_sort.vo.Answer_sortVo;

public class Answer_sortDaoImpl extends GeneralDaoImpl implements Answer_sortDao {

	@SuppressWarnings("unchecked")
	@Override
	public List<Answer_sortVo> search(PageBean pageBean, String parent_code) throws Exception {
		Map<String,Object> params = new HashMap<String,Object>();
		StringBuilder hql = new StringBuilder("from Answer_sort where flag=0");
		if(parent_code != null && !parent_code.equals("")) {
			hql.append(" and parent_num=:parent_num");
			params.put("parent_num", parent_code);
		} else {
			hql.append(" and parent_num is null");
		}
		List<Answer_sortVo> d = new ArrayList<Answer_sortVo>();
		List<Answer_sort> l = hibernateHandler.query(hql, pageBean, params);
		for(Answer_sort bean : l) {
			Answer_sortVo dv = new Answer_sortVo();
			BeanUtils.copyProperties(bean, dv);
			d.add(dv);
		}
		return d;
	}

	@Override
	public void insert(Answer_sortVo bean) throws Exception {
		Answer_sort pojo = new Answer_sort();
		BeanUtils.copyProperties(bean, pojo);
		hibernateHandler.insert(pojo);
	}

	@Override
	public void update(Answer_sortVo bean) throws Exception {
		Answer_sort pojo = (Answer_sort)hibernateHandler.find(Answer_sort.class, bean.getAnswer_sort_id());
		BeanUtils.copyProperties(bean, pojo);
		hibernateHandler.update(pojo);
	}

	@Override
	public void updateFlag(Answer_sortVo bean) throws Exception {
		update(bean);
	}

	@Override
	public Answer_sortVo find(Integer id) throws Exception {
		Answer_sort pojo = (Answer_sort)hibernateHandler.find(Answer_sort.class, id);
		Answer_sortVo bean = new Answer_sortVo();
		BeanUtils.copyProperties(pojo, bean);
		return bean;
	}
}
